package com.edu.zju.scs.panacea.controller.manage;


import com.edu.zju.scs.panacea.entity.BaseResult;
import com.edu.zju.scs.panacea.entity.manage.Admin;
import com.edu.zju.scs.panacea.entity.plan.Seller;
import com.edu.zju.scs.panacea.entity.resource.Site;
import com.edu.zju.scs.panacea.service.manage.AdminService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@EnableAutoConfiguration
public class AdminController {

    @Autowired
    private AdminService adminService;

    @ResponseBody
    @ApiOperation(value="管理员登录", notes="管理员登录")
    @RequestMapping(value = "/admin/login", method = RequestMethod.GET)
    public BaseResult agentALogin(
            @ApiParam("用户名") @RequestParam(value = "name") String name,
            @ApiParam("密码") @RequestParam(value = "password") String password,
            HttpSession session) {
        return adminService.isAdmin(name, password, session);
    }


    @ResponseBody
    @ApiOperation(value="获得登录用户", notes="获得登录用户")
    @RequestMapping(value = "/loginer", method = RequestMethod.GET)
    public BaseResult getLoginer(
            @ApiParam("类型") @RequestParam(value = "type") Integer type,
            HttpSession session) {
        BaseResult baseResult = new BaseResult();
        if (type == 0) {
            Admin admin = (Admin) session.getAttribute("admin");
            baseResult.success(admin);
        }
        if (type == 1) {
            Seller seller = (Seller) session.getAttribute("seller");
            baseResult.success(seller);
        }
        if (type == 2) {
            Site site = (Site) session.getAttribute("site");
            baseResult.success(site);
        }
        return baseResult;
    }

}
